package itertools

import (
	"bufio"
)

// Iterator is an iteratable sequence that gives one item at a time.
type Iterator interface {
	// Next fetches the next value, if the end of iteration is met,
	// this method returns `false`.
	Next() bool
	// Err returns `error` if there is something bad happened when
	// fetching the next value.
	Err() error
	// Val returns the next value `Next` fetched.
	Val() interface{}
}

// Scanner is a wrapping for `*bufio.Scanner`.
type Scanner struct {
	*bufio.Scanner
}

// Next implments the `Iterator`.
func (s *Scanner) Next() bool {
	return s.Scanner.Scan()
}

// Err implments the `Iterator`.
func (s *Scanner) Err() error {
	return s.Scanner.Err()
}

// Val implments the `Iterator`.
func (s *Scanner) Val() interface{} {
	return s.Scanner.Bytes()
}
